#ifndef  _MYDECODER_H__
#define  _MYDECODER_H__

#include "global.h"
#include <string>

extern "C" {
//编码
#include "libavcodec/avcodec.h"
//封装格式处理
#include "libavformat/avformat.h"
//像素处理
#include "libswscale/swscale.h"
#include "libavfilter/avfilter.h"
#include "libavutil/imgutils.h"
#include "libavcodec/jni.h"
#include "libswresample/swresample.h"
#include "libavutil/opt.h"
}

class CMyDecoder
{
public:
    CMyDecoder();
    ~CMyDecoder();

    int OpenFile(std::string mediaUri);
    int GetFrameWH(int &nW,int &nH);
    int InitSws(AVFrame *pFrameOut);
    int GetFrameData(AVFrame *pFrameOut,AVFrame *pFrameOut_a,enMediaType &enMT,double &pts);
    void GetAudioData(AVFrame *pFrame, unsigned char *pData, int &nDataLen);
    int                 GetMediaInfo(SMediaInfo &tagInfo);
    void                SetFilterInfo(SMediaInfo &tagInfo);
    void				SetOutSwrInfo(SMediaInfo &tagInfo);

private:
    int                 InitFilters(const char *filters_descr);
    int                 InitAudioFilters();

    AVFormatContext *m_pFormatCtx;
    int             m_streamIdx;
    int             m_streamIdx_a;
    AVCodecContext  *m_pCodecCtx;
    AVCodecContext  *m_pCodecCtx_a;
    AVCodecParameters *m_pavCodecParameters;
    AVCodecParameters *m_pavCodecParameters_a;
    AVCodec         *m_pCodec;
    AVCodec         *m_pCodec_a;
    AVFrame         *m_pFrame;
    AVPacket        *m_packet;

    //audio filter
    AVFilterContext     *m_buffersink_ctx;
    AVFilterContext     *m_buffersrc_ctx;
    AVFilterGraph       *m_filter_graph;

    //audio swr
    SwrContext			*m_audio_convert_ctx;

    //size buffer
    uint8_t *m_pout_buffer;
    SwsContext *m_pimg_convert_ctx;

    int             m_nFrameW;
    int             m_nFrameH;

    SMediaInfo          m_tagFilterInfo;
    SMediaInfo			m_tagSwrInfo;
};

#endif